package com.rfchina.okr.xianren.manager;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

public class ExecutorServiceManager {

	private ExecutorServiceManager() {
	}

	private static final ExecutorServiceManager single = new ExecutorServiceManager();

	public static ExecutorServiceManager getInstance() {
		return single;
	}

	ExecutorService singleThread = Executors.newSingleThreadExecutor();

	ScheduledExecutorService pool = Executors.newScheduledThreadPool(2);

	public void singleThreadExecute(Runnable command) {
		singleThread.execute(command);
	}

	// 从开始时间固定间隔
	public void scheduleAtFixedRate(Runnable command, long initialDelay, long period) {
		pool.scheduleAtFixedRate(command, initialDelay, period, TimeUnit.SECONDS);
	}

	// 从结束固定间隔
	public void scheduleWithFixedDelay(Runnable command, long initialDelay, long delay) {
		pool.scheduleWithFixedDelay(command, initialDelay, delay, TimeUnit.SECONDS);
	}
}
